package com.gitee.baqkft.code.ui.component;

import java.awt.GridBagLayout;

import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import com.gitee.baqkft.code.model.DataTableListModel;
import com.gitee.baqkft.code.model.DataTableModel;
import com.gitee.baqkft.code.ui.layout.GBC;
import com.gitee.baqkft.code.ui.utils.ViewUtils;

/**
 * 数据表列表和详情
 * @author chenmingcai
 * @date 2018年5月19日 下午3:27:32 
 *
 */
public class ListAndDetailPanel extends JPanel
{
	private static final long serialVersionUID = 1L;

	/**
	 * 数据表列表
	 */
	private JList<String> tableList;
	
	/**
	 * 数据表详情
	 */
	private JTable detailTable;
	
	public ListAndDetailPanel()
	{
		setLayout(new GridBagLayout());
		
		tableList = new JList<String>(new DataTableListModel(null)); 
		JScrollPane scollPanel = new JScrollPane(tableList);
		GBC gbc = new GBC(0, 0, 40, 1).setWeight(1, 1).setFill(GBC.BOTH);
		add(scollPanel, gbc);
		
		//创建数据表详情界面
		detailTable = new JTable(new DataTableModel(null));
		scollPanel = new JScrollPane(detailTable);
		gbc = new GBC(40, 0).setWeight(3, 1).setFill(GBC.BOTH).setInsets(0, 0, 0, 10);
		add(scollPanel, gbc);
		
		int txtHeight = ViewUtils.measureHeight("HELLO", detailTable.getFont());
		detailTable.setRowHeight(txtHeight + 10);
	}

	/**
	 * 获取列表
	 * @return
	 */
	public JList<String> getTableList()
	{
		return tableList;
	}

	/**
	 * 获取详情表
	 * @return
	 */
	public JTable getDetailTable()
	{
		return detailTable;
	}
}
